﻿using Liang.DataBase.DAL;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;

namespace Liang.DataBase.Helper
{
    public class BaseManagerDao
    {
        public Type myType { get; set; }

        public DbContext context;

        public BaseManagerDao(Type myType)
        {
            this.myType = myType;
            this.context = new DBEntities();
        }

        /// <summary>
        /// 根据Type删除对应的数据对象
        /// </summary>
        /// <param name="o">要删除的对象</param>
        public void deleteItem(object o)
        {
            object obj = null;
            try
            {
                obj = context.Set(myType).Find(o);
                context.Set(myType).Remove(obj);
                context.SaveChanges();
            }
            catch
            {
                throw new Exception("该数据已使用，无法删除！");
            }
        }
    }
}
